package stdying.handyweibo.openapi;

import android.content.Context;
import android.content.SharedPreferences;

/**
 * Description: token 分类信息
 * Author: liulili
 * Created: 2015-11-21
 */
public class TokenSession {
    private static final String PREFERENCES_NAME = "openapi_type";
    private static final String TYPE = "type";
    public static final int TOKEN_TYPE_WEIBO = 1;

    /**
     * 保存登录类型
     * @param context
     * @param type
     * @return
     */
    public static boolean savaTokenType(Context context,int type){
        if((null == context) || (type < 0)){
            return false;
        }
        SharedPreferences sharedPreferences = context.getSharedPreferences(PREFERENCES_NAME,Context.MODE_PRIVATE);
        SharedPreferences.Editor editor = sharedPreferences.edit();
        editor.putInt(TYPE,type);
        return editor.commit();
    }

    /**
     * 获取token类型
     * @param context
     * @return
     */
    public static int getTokenType(Context context){
        if((null == context)){
            return -1;
        }
        SharedPreferences sharedPreferences = context.getSharedPreferences(PREFERENCES_NAME,Context.MODE_PRIVATE);
        return sharedPreferences.getInt(TYPE,-1);
    }
}

